
# *******************************************************************************************
# *******************************************************************************************
#        REQUIRED PARAMETERS from  "makensis.exe" <-- nsisAnt.jar <-- ant build.xml
# *******************************************************************************************
# *******************************************************************************************
# BUILD_TIMESTAMP 
# PRODUCT_NAME 
# PRODUCT_VERSION 
# PRODUCT_EXE 
# PRODUCT_JAR 

# *******************************************************************************************
# *******************************************************************************************
#               CONSTANTS
# *******************************************************************************************
# *******************************************************************************************

# top-level developer folder(relative to this nsis .nis file)
!define DEVELOP_HOME_DIR "."

# FileName Constants
!define PRODUCT_INSTALLER_NAME "${PRODUCT_NAME}_${PRODUCT_VERSION}_${BUILD_TIMESTAMP}_Setup.exe"
!define UNINSTALLER_EXE_NAME "Uninstall.exe"
!define JFLIGHTLOG_LICENSE "LICENSE.txt"
!define RELEASE_NOTES "README.txt"
!define JFLIGHTLOG_BUILD_FILE "build.xml"
!define JFLIGHTLOG_INSTALLER_SCRIPT "AcmeBoundingBoxInstaller.nsi"


# Directory Constants
!define INSTALL_DIR_DEFAULT "${PRODUCT_NAME}_${PRODUCT_VERSION}"

# Shortcuts Constants
!define PRODUCT_STARTMENU_DIR "${PRODUCT_NAME}_${PRODUCT_VERSION}"
!define START_MENU_EXE_LABEL "${PRODUCT_NAME} ${PRODUCT_VERSION}"
!define DESKTOP_EXE_SHORTCUT_NAME "${START_MENU_EXE_LABEL}"
!define PRODUCT_WEB_SITE "http://jflightlog.com"
!define PRODUCT_PUBLISHER "RIF"

# *******************************************************************************************
# *******************************************************************************************
#               CONFIG SETTINGS
# *******************************************************************************************
# *******************************************************************************************

SetCompressor lzma


!include MUI2.nsh
#!define MUI_COMPONENTSPAGE_SMALLDESC

!define MUI_FINISHPAGE_NOAUTOCLOSE
!define MUI_UNFINISHPAGE_NOAUTOCLOSE

!define MUI_ABORTWARNING
!define MUI_UNABORTWARNING

!define MUI_ICON "${NSISDIR}\Contrib\Graphics\Icons\modern-install.ico"
!define MUI_UNICON "${NSISDIR}\Contrib\Graphics\Icons\modern-uninstall.ico"

#!define MUI_WELCOMEFINISHPAGE_BITMAP "${DEVELOP_HOME_DIR}\resources\img\JFltLogInstallerSidePanel.bmp"
#!define MUI_UNWELCOMEFINISHPAGE_BITMAP "${DEVELOP_HOME_DIR}\resources\img\JFltLogInstallerSidePanel.bmp"

#!define MUI_ICON "${DEVELOP_HOME_DIR}\resources\img\arrowIcon.ico"
#!define MUI_UNICON "${DEVELOP_HOME_DIR}\resources\img\deleteIcon.ico"

# *******************************************************************************************
# *******************************************************************************************
#               INSTALLER PAGES
# *******************************************************************************************
# *******************************************************************************************
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_LICENSE "${DEVELOP_HOME_DIR}/${JFLIGHTLOG_LICENSE}"
!insertmacro MUI_PAGE_DIRECTORY
#!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_INSTFILES

#set settings for the finishpage macro before we insert it
!define MUI_FINISHPAGE_RUN "$INSTDIR\${PRODUCT_EXE}"
!define MUI_FINISHPAGE_SHOWREADME "$INSTDIR\${RELEASE_NOTES}"
!define MUI_FINISHPAGE_SHOWREADME_NOTCHECKED

!insertmacro MUI_PAGE_FINISH

#UNinstaller pages
!insertmacro MUI_UNPAGE_WELCOME
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES
!insertmacro MUI_UNPAGE_FINISH

!insertmacro MUI_LANGUAGE "English"

/*
#Set Section descriptions(for mouseOver hover)
LangString DESC_JFlightLogCore ${LANG_ENGLISH} "JFlightLog Core Component"
LangString DESC_JFlightLogUnInstaller ${LANG_ENGLISH} "UnInstaller"
LangString DESC_JFlightLogShortCuts ${LANG_ENGLISH} "Start Menu & Desktop Shortcuts"

!insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
  !insertmacro MUI_DESCRIPTION_TEXT ${JFlightLogCore} $(JFlightLogCore)
  !insertmacro MUI_DESCRIPTION_TEXT ${Section2} $(DESC_Section2)
!insertmacro MUI_FUNCTION_DESCRIPTION_END
*/

Name "${PRODUCT_NAME} ${PRODUCT_VERSION}"
#BrandingText "${PRODUCT_NAME} ${PRODUCT_VERSION}"
BrandingText " "

# put the installer in an 'output' folder to keep things neat
OutFile "${DEVELOP_HOME_DIR}\output\${PRODUCT_INSTALLER_NAME}"
InstallDir "$PROGRAMFILES\${INSTALL_DIR_DEFAULT}"
ShowInstDetails show
ShowUnInstDetails show

# *******************************************************************************************
# *******************************************************************************************
#               INSTALLER SECTIONS -- run when the user INstalls
# *******************************************************************************************
# *******************************************************************************************
Section "JFlightLog Core" JFlightLogCore

  SetOutPath "$INSTDIR"
  SetOverwrite on

  File "${DEVELOP_HOME_DIR}\${PRODUCT_EXE}"
  File "${DEVELOP_HOME_DIR}\${PRODUCT_JAR}"

  #include the Ant build file :)
  File "${DEVELOP_HOME_DIR}\${JFLIGHTLOG_BUILD_FILE}"
  #include the installer script :)
  File "${DEVELOP_HOME_DIR}\${JFLIGHTLOG_INSTALLER_SCRIPT}"

  SetOutPath "$INSTDIR\lib"
  #include lib jars, but not subversion folders
  File /r /x .svn "${DEVELOP_HOME_DIR}\lib\*.*"

  SetOutPath "$INSTDIR\res"
  File /r /x .svn /x build "${DEVELOP_HOME_DIR}\res\*.*"

  SetOutPath "$INSTDIR\doc"
  File /r /x .svn "${DEVELOP_HOME_DIR}\doc\*.*"

  SetOutPath "$INSTDIR\src"
  File /r /x .svn "${DEVELOP_HOME_DIR}\src\*.*"
SectionEnd

# the dash '-' means it's hidden
Section "-Uninstaller" JFlightLogUnInstaller
  WriteUninstaller "$INSTDIR\${UNINSTALLER_EXE_NAME}"
SectionEnd

#----------------------------------------------------------------------------
#             Shortcuts Section(Start menu and Desktop)
#----------------------------------------------------------------------------
# the dash '-' means it's hidden
Section "-Shortcuts" JFlightLogShortCuts
  #non-intuitive nsis quirk, we have to set the outputpath for the shortcuts
  #  just like we do for files
  SetOutPath "$INSTDIR"
  # Start Menu
  CreateDirectory "$SMPROGRAMS\${PRODUCT_STARTMENU_DIR}"
  CreateShortCut "$SMPROGRAMS\${PRODUCT_STARTMENU_DIR}\${START_MENU_EXE_LABEL}.lnk" "$INSTDIR\${PRODUCT_EXE}"
  # Shortcut to the UnInstaller
  CreateShortCut "$SMPROGRAMS\${PRODUCT_STARTMENU_DIR}\Uninstall.lnk" "$INSTDIR\${UNINSTALLER_EXE_NAME}"
  # Desktop
  CreateShortCut "$DESKTOP\${DESKTOP_EXE_SHORTCUT_NAME}.lnk" "$INSTDIR\${PRODUCT_EXE}"
  # add a link to the jflightlog.com website
  WriteIniStr "$INSTDIR\${PRODUCT_NAME}.url" "InternetShortcut" "URL" "${PRODUCT_WEB_SITE}"
  CreateShortCut "$SMPROGRAMS\${PRODUCT_STARTMENU_DIR}\Website.lnk" "$INSTDIR\${PRODUCT_NAME}.url"
SectionEnd


 #****************************************************************************************
 #****************************************************************************************
 #   THE PROBLEM IS THAT Sun uses who knows what version of InstallShield in their jre installer
       # and that InstallShield doesn't accept INSTALLDIR cmd parm values that have a space
       #  in the dir name!!!! like "program files" ... (why would someone want to install there? ;)
 #*********************************************************************************************************
#  DetailPrint "Installing Java Runtime Environment"
  #ExecWait "$INSTDIR\lib\jre\jre-1_5_0_06-windows-i586-p.exe /s /v$\"/qn INSTALLDIR=$INSTDIR\lib\jre"
  #/s /v"/qb- IEXPLORER=1 MOZILLA=1 REBOOT=Suppress JAVAUPDATE=0
  # this ~works, but it ignores the the
  #ExecWait '$INSTDIR\lib\JRE\jre-1_5_0_06-windows-i586-p.exe /s /v"/qb- IEXPLORER=0 MOZILLA=0 INSTALLDIR=$INSTDIR\lib\JRE REBOOT=Suppress JAVAUPDATE=0'
#  ExecWait '$INSTDIR\lib\JRE\jre-6u10-windows-i586-p.exe /s INSTALLDIR="$INSTDIR\lib\JRE\"'
#  ExecWait '$INSTDIR\lib\JRE\jre-6u10-windows-i586-p.exe /s INSTALLDIR=.'

  #qb- IEXPLORER=1 MOZILLA=1 REBOOT=Suppress JAVAUPDATE=0


# *******************************************************************************************
# *******************************************************************************************
#               UNINSTALLER SECTION -- run when the user UNinstalls
# *******************************************************************************************
# *******************************************************************************************
Section Uninstall
  #nsis quirk:  delete the uninstaller.exe file itself first
  Delete "$INSTDIR\${UNINSTALLER_EXE_NAME}"
  Delete "$INSTDIR\${PRODUCT_NAME}.url" #the website
  Delete "$INSTDIR\${PRODUCT_JAR}"
  Delete "$INSTDIR\${PRODUCT_EXE}"
  Delete "$INSTDIR\${JFLIGHTLOG_BUILD_FILE}"
  Delete "$INSTDIR\${JFLIGHTLOG_INSTALLER_SCRIPT}"

  RMDir /r "$INSTDIR\lib"
  RMDir /r "$INSTDIR\res"
  RMDir /r "$INSTDIR\doc"
  RMDir /r "$INSTDIR\src"

  #only succeeds if empty dir(what we want)
  RMDir "$INSTDIR"

  Delete "$DESKTOP\${DESKTOP_EXE_SHORTCUT_NAME}.lnk"
  # delete the start menu dir we made(and its contents)
  RMDir /r "$SMPROGRAMS\${PRODUCT_STARTMENU_DIR}"
SectionEnd

